package demo4;

abstract class Animals{

    public String name;

    //插入构造方法的快捷键为：Alt + insert
    public Animals(String name) {
        this.name = name;
    }
}

interface IRunning{
    void run();
}

interface ISwimming{
    void swim();
}
interface IFlying{
    void fly();
}

//只能先 “继承” 再  “实现”
class Dog extends Animals implements IRunning{
    public Dog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "正在用四条腿跑！！！");
    }
}

class Fish extends Animals implements ISwimming{

    public Fish(String name) {
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(name + "正在游！！！");
    }
}

class bird extends Animals implements IFlying{

    public bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(name + "正在飞！！！");
    }
}

//类可以通过 extends 继承一个普通类/抽象类，同时通过 implements 实现多个接口
class Duck extends Animals implements IFlying,ISwimming,IRunning{

    public Duck(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "正在用两条腿跑！！！");
    }

    @Override
    public void swim() {
        System.out.println(name + "正在用两条腿游泳！！！");
    }

    @Override
    public void fly() {
        System.out.println(name + "正在用翅膀飞！！！");
    }
}

class Robot implements IRunning{

    @Override
    public void run() {
        System.out.println("机器人正在用机器腿跑步！！！");
    }
}

public class Text {

    /**
     * 只要实现了 IRunning 接口的  都可以接收
     * @param iRunning
     */
    public static void walk(IRunning iRunning){
        iRunning.run();
    }
    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void fly(IFlying iFlying){
        iFlying.fly();
    }

    public static void main(String[] args) {
        walk(new Dog("旺财"));
        walk(new Duck("呆瓜1"));
        walk(new Robot());

        System.out.println("========");

        swim(new Fish("狗剩"));
        swim(new Duck("呆瓜2"));

        System.out.println("========");

        fly(new bird("苍穹"));
        fly(new Duck("呆瓜3"));
    }
}
